package com.fl.proyect_softmedic;

import com.example.proyect_softmedic.R;
import android.os.Bundle;
import android.app.Activity;
import android.content.res.Resources;
import android.view.Gravity;
import android.widget.EditText;
import android.widget.TableLayout;
import android.widget.TableRow;
import android.widget.TextView;


public class DetailSchedulle extends Activity {
	
	
	private TableLayout tblschedulle_header;//layout para la fila de encabezado
	//private TableLayout tbldetail_schedulle;// layout para la fila de resultado o registro consultado
    private TableRow.LayoutParams layoutFila;// layout para asignar dimensiones a la fila
    private TableRow.LayoutParams layoutLong;// layout para asignar dimensiones a la fila
    private TableRow.LayoutParams layoutDefault; 
    private TableRow fila_schedulle; // fila para mostrar el resultado o registro consultado
    private Resources rs;// variable para acceder a los objetos relacionados de la clase R como son los string
    
    private EditText dataini , datafin;
    

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.detail_schedulle_activity);
		
		rs = this.getResources();
		tblschedulle_header = (TableLayout)findViewById(R.id.schedulle_selected);
       // tbldetail_schedulle = (TableLayout)findViewById(R.id.tbldetailschedulle);
        layoutFila = new TableRow.LayoutParams(TableRow.LayoutParams.WRAP_CONTENT,TableRow.LayoutParams.WRAP_CONTENT);
        layoutLong = new TableRow.LayoutParams(130,TableRow.LayoutParams.WRAP_CONTENT);
        layoutDefault = new TableRow.LayoutParams(100,TableRow.LayoutParams.WRAP_CONTENT);
        
        dataini = (EditText)findViewById(R.id.editxtDateini_ds);
        dataini.setKeyListener(null);
        datafin = (EditText)findViewById(R.id.editxtDatefinal_ds);
        datafin.setKeyListener(null);
        
        addheader();
        setregister("29-08-2013", "Jueves", "8:00", "12:00", "13:00", "17:00");
	}
	
	
	public void addheader(){
		//se definen los objetos a utilizar	
		TableRow fila;		
		TextView date_schedulle = new TextView(this);
		TextView day_week = new TextView(this);
		TextView amfrom = new TextView(this);
		TextView amto = new TextView(this);
		TextView pmfrom = new TextView(this);
		TextView pmto = new TextView(this);
		
		//se asigna el valor del objeto fila y se le asigna el layout fila
		 fila = new TableRow(this);
		 fila.setLayoutParams(layoutFila);

		 //se asigna propiedades a el objeto txtid
		 date_schedulle.setText(rs.getString(R.string.txtvdate_quote));
		 date_schedulle.setGravity(Gravity.CENTER_HORIZONTAL);
		 date_schedulle.setTextAppearance(this,R.style.etiqueta);
		 date_schedulle.setBackgroundResource(R.drawable.styles_edittext);
		 date_schedulle.setLayoutParams(layoutLong);

		//se asigna propiedades a el objeto day_week
		 day_week.setText(rs.getString(R.string.txtvday_week));
		 day_week.setGravity(Gravity.CENTER_HORIZONTAL);
		 day_week.setTextAppearance(this,R.style.etiqueta);
		 day_week.setBackgroundResource(R.drawable.styles_edittext);
		 day_week.setLayoutParams(layoutDefault);
		 
		//se asigna propiedades a el objeto amfrom
		 amfrom.setText(rs.getString(R.string.txtvhour_am__from));
		 amfrom.setGravity(Gravity.CENTER_HORIZONTAL);
		 amfrom.setTextAppearance(this,R.style.etiqueta);
		 amfrom.setBackgroundResource(R.drawable.styles_edittext);
		 amfrom.setLayoutParams(layoutDefault);
		 
		//se asigna propiedades a el objeto amto
		 amto.setText(rs.getString(R.string.txtvhour_am__to));
		 amto.setGravity(Gravity.CENTER_HORIZONTAL);
		 amto.setTextAppearance(this,R.style.etiqueta);
		 amto.setBackgroundResource(R.drawable.styles_edittext);
		 amto.setLayoutParams(layoutDefault);
		 
		//se asigna propiedades a el objeto pmfrom
		 pmfrom.setText(rs.getString(R.string.txtvhour_pm__from));
		 pmfrom.setGravity(Gravity.CENTER_HORIZONTAL);
		 pmfrom.setTextAppearance(this,R.style.etiqueta);
		 pmfrom.setBackgroundResource(R.drawable.styles_edittext);
		 pmfrom.setLayoutParams(layoutDefault);
		 
		//se asigna propiedades a el objeto pmto
		 pmto.setText(rs.getString(R.string.txtvhour_pm__to));
		 pmto.setGravity(Gravity.CENTER_HORIZONTAL);
		 pmto.setTextAppearance(this,R.style.etiqueta);
		 pmto.setBackgroundResource(R.drawable.styles_edittext);
		 pmto.setLayoutParams(layoutDefault);

		 // se asignan cada uno de los objetos a la fila
		 fila.addView(date_schedulle);
		 fila.addView(day_week);
		 fila.addView(amfrom);
		 fila.addView(amto);
		 fila.addView(pmfrom);
		 fila.addView(pmto);
		 tblschedulle_header.addView(fila);
		    }
		//muestra los botones dependiendo del roll del usuario
	public void setregister(String date, String dayw, String am1, String am2, String pm1, String pm2){
		 
		 TextView dateschedull = new TextView(this);
	     TextView dayweek = new TextView(this);
	     TextView ham1 = new TextView(this);
	     TextView ham2 = new TextView(this);
	     TextView hpm1 = new TextView(this);
	     TextView hpm2 = new TextView(this);
	     
	    fila_schedulle = new TableRow(this);
	    fila_schedulle.setLayoutParams(layoutFila);
	    
        dateschedull.setText(date);
        dateschedull.setGravity(Gravity.CENTER_HORIZONTAL);
        dateschedull.setTextAppearance(this,R.style.etiqueta);
        dateschedull.setBackgroundResource(R.drawable.tabla_celda);
        dateschedull.setLayoutParams(layoutLong);
        
        dayweek.setText(dayw);
        dayweek.setGravity(Gravity.CENTER_HORIZONTAL);
        dayweek.setTextAppearance(this,R.style.etiqueta);
        dayweek.setBackgroundResource(R.drawable.tabla_celda);
        dayweek.setLayoutParams(layoutDefault);
        
        ham1.setText(am1);
        ham1.setGravity(Gravity.CENTER_HORIZONTAL);
        ham1.setTextAppearance(this,R.style.etiqueta);
        ham1.setBackgroundResource(R.drawable.tabla_celda);
        ham1.setLayoutParams(layoutDefault);
        
        ham2.setText(am2);
        ham2.setGravity(Gravity.CENTER_HORIZONTAL);
        ham2.setTextAppearance(this,R.style.etiqueta);
        ham2.setBackgroundResource(R.drawable.tabla_celda);
        ham2.setLayoutParams(layoutDefault);
        
        hpm1.setText(pm1);
        hpm1.setGravity(Gravity.CENTER_HORIZONTAL);
        hpm1.setTextAppearance(this,R.style.etiqueta);
        hpm1.setBackgroundResource(R.drawable.tabla_celda);
        hpm1.setLayoutParams(layoutDefault);
        
        hpm2.setText(pm2);
        hpm2.setGravity(Gravity.CENTER_HORIZONTAL);
        hpm2.setTextAppearance(this,R.style.etiqueta);
        hpm2.setBackgroundResource(R.drawable.tabla_celda);
        hpm2.setLayoutParams(layoutDefault);
        
       
        fila_schedulle.addView(dateschedull);        
        fila_schedulle.addView(dayweek);
        fila_schedulle.addView(ham1);
        fila_schedulle.addView(ham2);
        fila_schedulle.addView(hpm1);
        fila_schedulle.addView(hpm2);
        
        tblschedulle_header.addView(fila_schedulle);
	}
	//agrega la primera fila de registros
}
